#include "glaxes.h"
#include "glstring.h"


void GL_DrawAxes(GLfloat viewRange)
{
    // light parameteres
    GLfloat ax_specular[4] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat ax_diffuse[4]= { 0.8, 0.1, 0.0, 1.0 };
    GLfloat ax_shininess[] = { 150.0 };
    GLfloat ax_light0_position[] = { 50.0, 50.0, 50.0, 0.0 };
    
    // color parameters
    static float r[4] = {0.9, 0.0, 0.0, 0.8};
    static float g[4] = {0.0, 0.9, 0.0, 0.8};
    static float b[4] = {0.0, 0.0, 0.9, 0.9};
    
    // axes geometry sizes
    float axLong = 0.07 * viewRange;
    float axRadi = 0.3;
    float coLong = 1.2;
    float coRadi = 0.5;
    GLUquadric *axQuad=gluNewQuadric();

    // method 1: draw easy line axes
    /*
    glColor3fv(gray);
    glBegin(GL_LINES);
        glVertex3f(0.0,0.0,0.0);
        glVertex3f(0.1*viewRange,0.0,0.0);
    glEnd();
    glBegin(GL_LINES);
        glVertex3f(0.0,0.0,0.0);
        glVertex3f(0.0,0.1*viewRange,0.0);
    glEnd();
    glBegin(GL_LINES);
        glVertex3f(0.0,0.0,0.0);
        glVertex3f(0.0,0.0,0.1*viewRange);
    glEnd();
    */

    // method 2: draw 3D solid axes
    glMaterialfv(GL_FRONT, GL_DIFFUSE, ax_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, ax_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, ax_shininess);
    glLightfv(GL_LIGHT0, GL_POSITION, ax_light0_position);
    
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    
    // Z-Axis
    glPushMatrix();
    glColor4fv(r);
    gluCylinder(axQuad,axRadi,axRadi,axLong,20,20);
    glTranslatef(0,0,axLong);
    glutSolidCone(coRadi,coLong,20,20);
    //glutPrint(1.0f, 1.0f, "Z", 1.0f, 0.0f, 0.0f, 0.5f);	
    glPopMatrix();

    // X-Axis
    glPushMatrix();
    glColor4fv(g);
    glRotatef(90, 0, 1, 0);
    gluCylinder(axQuad,axRadi,axRadi,axLong,20,20);
    glTranslatef(0,0,axLong);
    glutSolidCone(coRadi,coLong,20,20);
	//glutPrint(1.0f, 1.0f, "X", 1.0f, 0.0f, 0.0f, 0.5f);	
    glPopMatrix();

    // Y-Axis
    glPushMatrix();
    glColor4fv(b);
    glRotatef(-90, 1, 0, 0);
    gluCylinder(axQuad,axRadi,axRadi,axLong,20,20);
    glTranslatef(0,0,axLong);
    glutSolidCone(coRadi,coLong,20,20);
	//glutPrint(1.0f, 1.0f, "Y", 0.0f, 1.0f, 0.0f, 0.5f);	
    glPopMatrix();

    glDisable(GL_LIGHTING);
}


